package cn.it.hbtt.daoimg;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;

import cn.it.hbtt.dao.BaseDAO;
import cn.it.hbtt.entity.User;
/**
 * 
 * @author 永恒
 *向订单数据库中添加数据
 */
public class Orderimg {
	public  void m(int userId,String loginName,String userAddress,String createTime,float cost,String serialNumber ) {
		try {
			//PrintWriter out=response.getWriter();
			
			BaseDAO base=new BaseDAO();
			Connection conn=base.getConnection();

			Statement stm = conn.createStatement();
			ResultSet rs = stm.executeQuery("select * from easybuy_order");
	
			String sql = "insert into easybuy_order (userId,loginName,createTime,cost,serialNumber) values(?,?,?,?,?)";
			PreparedStatement ps = conn.prepareStatement(sql);
			ps.setInt(1, userId);
			// 为sql语句中的问号赋值
			ps.setString(2, loginName);
			
			ps.setString(3, createTime);
			ps.setFloat(4, cost);
			ps.setString(5,serialNumber);
			// 执行sql语句
            ps.executeUpdate();
            // 关闭数据库连接对象
			conn.close();
			
			
			
			
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		
		
		
	}

	/**
	 * 提交订单的时候删除购物车数据
	 * @param id
	 */
public void drop_order(int id) {
	try {
		BaseDAO base=new BaseDAO();
		Connection conn=base.getConnection();
		Statement stm = conn.createStatement();
		
		ResultSet rs = stm.executeQuery("select * from easybuy_buycar");

		
			String sql = "DELETE FROM `easybuy_buycar` WHERE `id`="+id;
			PreparedStatement ps = conn.prepareStatement(sql);
		
			// 执行sql语句
            ps.executeUpdate();
            // 关闭数据库连接对象
			conn.close();
		
		
		
	} catch (Exception e) {
		// TODO: handle exception
	}
	
}

}
